# -*- coding: utf-8 -*-
# !/usr/bin/env python
"""
-------------------------------------------------
   File Name：     common
   Description :   
   Author :       lth
   date：          2022/12/7
-------------------------------------------------
   Change Activity:
                   2022/12/7 9:43: create this script
-------------------------------------------------
"""
__author__ = 'lth'

import numpy as np
import torch


def PE(x, L):
    pe = []
    for i in range(L):
        for fn in [torch.sin, torch.cos]:
            pe.append(fn(2 ** i  * x))
    return torch.cat(pe, -1)


class PositionEncoding:
    @staticmethod
    def encode(x, L):
        pe = []
        for i in range(L):
            for fn in [torch.sin, torch.cos]:
                pe.append(fn(2 ** (i + 1) * x))
        return torch.cat(pe, -1)
